package handle

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/context"
)

type Redirect struct {
}

func (r Redirect) InitRoute(party iris.Party) {
	p := party.Party("/trans")
	p.Get("/redirect", r.Redirect())
	p.Get("/exec", r.Exec())
	p.Get("/serveHttpc", r.ServeHTTPC())
	p.Get("/default", r.Default())
}
func (r Redirect) Redirect() iris.Handler {
	return func(ctx *context.Context) {
		ctx.Redirect("/trans/default", iris.StatusFound)
	}
}
func (r Redirect) ServeHTTPC() iris.Handler {
	return func(ctx *context.Context) {
		r := ctx.Request()
		r.URL.Path = "/trans/default"

		ctx.Application().ServeHTTPC(ctx)
	}
}
func (r Redirect) Exec() iris.Handler {
	return func(ctx *context.Context) {
		//r := ctx.Request()
		//r.URL.Path = "/trans/default"
		//ctx.Application().ServeHTTPC(ctx)
		ctx.Exec("GET", "/trans/default")
	}
}
func (r Redirect) Default() iris.Handler {
	return func(ctx *context.Context) {
		ctx.JSON(map[string]string{
			"name": "as",
		})
	}
}
